const fs = require("fs")
const filePath = __dirname + "/../../../middleware/";
function dealMiddleware(app) {
    //加载配置中间件
    if (app.config.middleware && app.config.middleware.length) {
        app.config.middleware.forEach((m) => {
            if (fs.existsSync(`${filePath}${m}.ts`)) {
                const fn = require(`${filePath}${m}`);
                app.use(fn);
            } else {
                throw new Error(`middleware [${m}] not found!`);
            }
        });
    }
}
module.exports =  dealMiddleware